package play.control_flow

class MyClass

fun main() {
    cases("Hello")
    cases(1)
    cases(0L)
    cases(MyClass())
    cases("hello")
}

fun cases(o: Any) {
    when (o) {
        1 -> println("$o One")
        "Hello" -> println("$o: Greeting")
        is Long -> println("$o: Long")
        !is String -> println("$o: Not a string")
        else -> println("$o: Unknown")
    }

    println(whenAssign("Hello"))
    println(whenAssign(3.4))
    println(whenAssign(1))
    println(whenAssign(MyClass()))
}

fun whenAssign(obj: Any): Any {
    return when (obj) {                   
        1 -> "one"                              
        "Hello" -> 1                            
        is Long -> false                        
        else -> 42                              
    }
}